<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
use Latrell\Geohash\Facades\Geohash;
use Illuminate\Support\Facades\Hash;

/**
 * 用户
 *
 * @author Miluo Huang
 *
 * @SWG\Model(id="Member")
 */
class Member extends Model implements AuthenticatableContract
{
	use Authenticatable, SoftDeletes ;

	protected $table = 'members';

	public static function boot()
	{
		parent::boot();

		static::saving(function ($model)
		{
			// 保存的时候自动对密码进行加密。
			if (isset($model->password) && Hash::needsRehash($model->password)) {
				$model->password = Hash::make($model->password);
			}
		});
	}

	/**
	 * 头像
	 */
	public function avatar()
	{
		return $this->belongsTo('App\Models\UserFile', 'avatar_id');
	}

}
